package com.skyolder.milkbee.domain;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * A SweepstakeExt. 抽奖活动
 * name 名称
 * detail 详情
 * poster 发起人
 * startAt 开始时间
 * endAt 结束时间
 * userId 用户ID
 * leaguerId 会员ID
 * 
 */
@Entity
@Table(name = "sweepstake")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class SweepstakeExt implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "name")
    private String name;

    @Column(name = "detail")
    private String detail;

    @Column(name = "poster")
    private String poster;

    @Column(name = "start_at")
    private ZonedDateTime startAt;

    @Column(name = "end_at")
    private ZonedDateTime endAt;

    @Column(name = "created_at")
    private ZonedDateTime createdAt;

    @Column(name = "user_id")
    private Long userId;

    @Column(name = "leaguer_id")
    private Long leaguerId;

    @OneToMany(mappedBy = "sweepstake", fetch = FetchType.EAGER)
    private Set<AwardExt> awardExts = new HashSet<>();
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public SweepstakeExt name(String name) {
        this.name = name;
        return this;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDetail() {
        return detail;
    }

    public SweepstakeExt detail(String detail) {
        this.detail = detail;
        return this;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getPoster() {
        return poster;
    }

    public SweepstakeExt poster(String poster) {
        this.poster = poster;
        return this;
    }

    public void setPoster(String poster) {
        this.poster = poster;
    }

    public ZonedDateTime getStartAt() {
        return startAt;
    }

    public SweepstakeExt startAt(ZonedDateTime startAt) {
        this.startAt = startAt;
        return this;
    }

    public void setStartAt(ZonedDateTime startAt) {
        this.startAt = startAt;
    }

    public ZonedDateTime getEndAt() {
        return endAt;
    }

    public SweepstakeExt endAt(ZonedDateTime endAt) {
        this.endAt = endAt;
        return this;
    }

    public void setEndAt(ZonedDateTime endAt) {
        this.endAt = endAt;
    }

    public ZonedDateTime getCreatedAt() {
        return createdAt;
    }

    public SweepstakeExt createdAt(ZonedDateTime createdAt) {
        this.createdAt = createdAt;
        return this;
    }

    public void setCreatedAt(ZonedDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public Long getUserId() {
        return userId;
    }

    public SweepstakeExt userId(Long userId) {
        this.userId = userId;
        return this;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getLeaguerId() {
        return leaguerId;
    }

    public SweepstakeExt leaguerId(Long leaguerId) {
        this.leaguerId = leaguerId;
        return this;
    }

    public void setLeaguerId(Long leaguerId) {
        this.leaguerId = leaguerId;
    }
    
    public Set<AwardExt> getAwardExts() {
        return awardExts;
    }

    public SweepstakeExt awardExts(Set<AwardExt> awardExts) {
        this.awardExts = awardExts;
        return this;
    }

    public SweepstakeExt addAwardExt(AwardExt awardExt) {
    	awardExts.add(awardExt);
    	//awardExt.setSweepstake(this);
        return this;
    }

    public SweepstakeExt removeAward(AwardExt awardExt) {
    	awardExts.remove(awardExt);
    	awardExt.setSweepstake(null);
        return this;
    }

    public void setAwardExts(Set<AwardExt> awardExts) {
        this.awardExts = awardExts;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        SweepstakeExt sweepstake = (SweepstakeExt) o;
        if (sweepstake.id == null || id == null) {
            return false;
        }
        return Objects.equals(id, sweepstake.id);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "SweepstakeExt{" +
            "id=" + id +
            ", name='" + name + "'" +
            ", detail='" + detail + "'" +
            ", poster='" + poster + "'" +
            ", startAt='" + startAt + "'" +
            ", endAt='" + endAt + "'" +
            ", createdAt='" + createdAt + "'" +
            ", userId='" + userId + "'" +
            ", leaguerId='" + leaguerId + "'" +
            '}';
    }
}
